//
//  LGSportAppointDetailController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/11/6.
//

#import "LGSportAppointDetailController.h"
//患者详情
#import "LGPatientDetailController_YHJK.h"
#import "LGPatientDetailController2.h"
//运动康复
//#import "LGPatientSportsController.h"
#import "LGOrderSportHeadView.h"
#import "LGOrderSportOrderCell.h"
@interface LGSportAppointDetailController ()<UITableViewDelegate,UITableViewDataSource>
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)LGOrderSportHeadView *headView;
/**   */
@property (nonatomic , strong)NSArray *titleArray;
/**   */
@property (nonatomic , strong)NSArray *contentArray;
@end

@implementation LGSportAppointDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.contentArray = @[@" ",@" ",@" ",@" "];
    self.titleArray = @[@"预约时间",@"预约时段",@"预约医生",@"预约地址"];
    self.navigationView.title = @"预约详情";
    [self.view addSubview:self.tableView];
    [self creatBottomView];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/visit.Visit/appointmentDetail" parameters:@{@"appointment_id":self.appointid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            self.headView.status = LGNSString(returnData[@"state"]);
            self.headView.statusName = LGNSString(returnData[@"state_name"]);
            self.headView.patientDic = returnData[@"patient"];
            self.contentArray = @[LGNSString(returnData[@"visit_date"]),[NSString stringWithFormat:@"%@ %@号",returnData[@"start_time"],returnData[@"appointment_no"]],LGNSString(returnData[@"doctor"][@"realname"]),LGNSString(returnData[@"visit_address"])];
            [self.tableView reloadData];
        }
    } error:^(NSError *error) {
        
    }];
}

//患者档案
-(void)checkPatientDetailAction{
    NSDictionary *tempDic = self.headView.patientDic;
    NSString *nodePage = LGNSString(tempDic[@"nodepage"]);
    if ([nodePage isEqualToString:@"1"]) {
        //市一慢阻肺
        LGPatientDetailController2 *controller = [[LGPatientDetailController2 alloc]init];
        controller.patientid = LGNSString(tempDic[@"patient_id"]);
        controller.levelid = LGNSString(tempDic[@"level_id"]);
        controller.diseaseCode = LGNSString(tempDic[@"disease_code"]);
        [self.navigationController pushViewController:controller animated:YES];
    }else{
        //其他
        LGPatientDetailController_YHJK *controller = [[LGPatientDetailController_YHJK alloc]init];
        controller.patientid = LGNSString(tempDic[@"patient_id"]);
        controller.levelid = LGNSString(tempDic[@"level_id"]);
        controller.diseaseCode = LGNSString(tempDic[@"disease_code"]);
        [self.navigationController pushViewController:controller animated:YES];
    }
}

//运动康复
-(void)checkPatientSportsAction{
//    LGPatientSportsController *controller = [[LGPatientSportsController alloc]init];
//    controller.patientid = LGNSString(self.headView.patientDic[@"patient_id"]);
//    [self.navigationController pushViewController:controller animated:YES];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGOrderSportOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.title = self.titleArray[indexPath.row];
    cell.content = self.contentArray[indexPath.row];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return viewPix(50);
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    LGCornerHeaderView *headView = [[LGCornerHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(50))];
    headView.backgroundColor = [UIColor clearColor];
    headView.topMargin = viewPix(5);
    UIButton *titleBtn = [UIButton buttonWithTitle:@" 预约信息" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#333333" imageName:@"订单详情-预约信息"];
    titleBtn.frame = CGRectMake(viewPix(32), viewPix(5), viewPix(200), viewPix(45));
    titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    titleBtn.userInteractionEnabled = NO;
    [headView addSubview:titleBtn];
    return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return viewPix(17);
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    LGCornerFooterView *footView = [[LGCornerFooterView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(17))];
    footView.backgroundColor = [UIColor clearColor];
    footView.bottomMargin = viewPix(5);
    return footView;
}


-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, topBarHeight, Screen_W, Screen_H-topBarHeight-viewPix(84)-bottomSafeBarHeight/4.0) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGOrderSportOrderCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = self.headView;
    }
    return _tableView;
}

-(LGOrderSportHeadView *)headView{
    if(!_headView){
        _headView = [[LGOrderSportHeadView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(262))];
        _headView.title = @"预约类型：运动评估";
    }
    return _headView;
}

-(void)creatBottomView{
    UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, Screen_H-viewPix(84)-bottomSafeBarHeight/4.0, Screen_W, viewPix(84)+bottomSafeBarHeight/4.0)];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    
    UIButton *patientBtn = [UIButton buttonWithTitle:@"患者档案" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:kThemeColor imageName:@""];
    patientBtn.frame = CGRectMake(viewPix(47), viewPix(8), viewPix(128), viewPix(46));
    patientBtn.layer.borderColor = [UIColor colorWithString:kThemeColor].CGColor;
    patientBtn.layer.borderWidth = 1;
    patientBtn.cornerRidus = 10;
    [patientBtn addTarget:self action:@selector(checkPatientDetailAction) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:patientBtn];
    
    UIButton *sportBtn = [UIButton buttonWithTitle:@"运动康复" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#FFFFFF" imageName:@""];
    sportBtn.frame = CGRectMake(Screen_W-viewPix(175), viewPix(8), viewPix(128), viewPix(46));
    sportBtn.backgroundColor = [UIColor colorWithString:kThemeColor];
    sportBtn.cornerRidus = 10;
    [sportBtn addTarget:self action:@selector(checkPatientSportsAction) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:sportBtn];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
